﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BasicCMS.Content
{
    /// <summary>
    /// 类容项
    /// </summary>
    public abstract class ContentPart : IContentData, IContentRender
    {
        public string Name { get; set; }

        public string UniqueName { get; set; }

        public HttpRequest Request { get { return HttpContext.Current.Request; } }

        public HtmlHelper Html { get; set; }

        public Controller Controller { get; set; }

        public abstract IDictionary<string, object> GetData();

        public abstract MvcHtmlString Render();

        public virtual void Build(FormCollection form)
        {
            Controller.ViewData[UniqueName] = form[UniqueName];
        }

        public virtual void Build(DataRow row)
        {
            if (row.Table.Columns.Contains(UniqueName))
            {
                Controller.ViewData[UniqueName] = row[UniqueName];
            }
        }
    }
}